package thread;
import java.util.Scanner;

/**
 * 编译器的优化~
 * 解决: 1. synchronized 保证原子性, 禁止指令重排
 *      2. volatile 保证内存可见性,手动禁止编译器优化
 */
public class TestDemo16 {
    public volatile static int isQuit = 0;
    public static void main(String[] args) {

        Thread t = new Thread(() -> {
            while (isQuit == 0) {

            }
            System.out.println("线程 t 执行结束!");
        });
        t.start();

        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入:");
        isQuit = scanner.nextInt();
        System.out.println("main 执行完毕");
    }
}
